package com.bawei.lib_common

import android.app.Application
import android.util.Log
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.lib_net.datastore.DataStoreUtils
import com.bawei.lib_storage.room.DBUtils
import com.hyphenate.chat.EMClient
import com.hyphenate.chat.EMOptions
import com.tencent.mmkv.MMKV
import com.tencent.rtmp.TXLiveBase
import com.tencent.rtmp.TXLiveBaseListener
import com.umeng.commonsdk.UMConfigure
import com.umeng.socialize.PlatformConfig
import me.jessyan.autosize.AutoSize
//import cn.jiguang.verifysdk.api.JVerificationInterface

open class BaseApp:Application() {
    override fun onCreate() {
        super.onCreate()




        try {
            DBUtils.init(this,"ivideo.db")
            Log.d("BaseApp", "数据库初始化成功")
        } catch (e: Exception) {
            Log.e("BaseApp", "数据库初始化失败: ${e.message}", e)
            e.printStackTrace()
        }

        ARouter.openLog()
        ARouter.openDebug()
        ARouter.init(this)

        // 初始化MMKV
        MMKV.initialize(this)

        //数据库初始化
        DataStoreUtils.init(this)

        //屏幕适配
        AutoSize.initCompatMultiProcess(this) // 适配多进程

        //友盟
        UMConfigure.init(this, "5a12384aa40fa3551f0001d1", "umeng", UMConfigure.DEVICE_TYPE_PHONE, "");
        //微信
        PlatformConfig.setWeixin("wxdc1e388c3822c80b","3baf1193c85774b3fd9d18447d76cab0")
        //QQ
        PlatformConfig.setQQZone("101830139","5d63ae8858f1caab67715ccd6c18d7a5")

        //腾讯云直播
        val licenceURL = "https://license.vod2.myqcloud.com/license/v2/1330987093_1/v_cube.license" // 获取到的 licence url
        val licenceKey = "c1e9efb4c0878f62532e737bf092b4e2" // 获取到的 licence key
        TXLiveBase.getInstance().setLicence(this, licenceURL, licenceKey)
        TXLiveBase.setListener(object : TXLiveBaseListener() {
            override fun onLicenceLoaded(result: Int, reason: String?) {
                super.onLicenceLoaded(result, reason)
                Log.i("tx", "onLicenceLoaded: result:$result, reason:$reason")
            }
        })


        //腾讯云
       val options = EMOptions()
        options.setAppKey("1147240925149934#ivideo");
        EMClient.getInstance().init(this, options);

        // 极光一键登录SDK初始化
//        JVerificationInterface.setDebugMode(true)
//        JVerificationInterface.init(this) { code, result ->
//            Log.d("JVerification", "init code = $code, result = $result")
//        }
    }
}